package com.oddfar.campus.business.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.oddfar.campus.business.domain.ClTcw;
import com.oddfar.campus.business.domain.ClTcw;
import com.oddfar.campus.business.domain.Tcwxx;
import com.oddfar.campus.common.core.BaseMapperX;
import com.oddfar.campus.common.core.LambdaQueryWrapperX;
import com.oddfar.campus.common.domain.PageResult;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface ClTcwMapper extends BaseMapperX<ClTcw> {


    default PageResult<ClTcw> selectPage(ClTcw clTcw) {

        return selectPage(new LambdaQueryWrapperX<ClTcw>()
                .eqIfPresent(ClTcw::getClpzh, clTcw.getClpzh())
                .eqIfPresent(ClTcw::getPhonenumber, clTcw.getPhonenumber())
                .orderByDesc(ClTcw::getJssj)
        );

    }

    default PageResult<ClTcw> selectPage(ClTcw clTcw, Long phonenumber) {

        return selectPage(new LambdaQueryWrapperX<ClTcw>()
                .eq(ClTcw::getPhonenumber, phonenumber)
                .eqIfPresent(ClTcw::getTcwid, clTcw.getTcwid())
                .likeIfPresent(ClTcw::getTcw, clTcw.getTcw())
        );

    }

    @Delete("DELETE FROM cl_tcw WHERE djxh in (#{uuid})")
    String deleteClTcw(String uuid);


    @Select("SELECT * FROM dj_tcwxx where dqkybz = '1' order by tcw")
    List<Tcwxx> dqkyztcx();

    @Select("SELECT tcw FROM dj_tcwxx WHERE tcwid = #{tcwid}")
    String selectTcwByTcwid(Long tcwid);

    @Select("SELECT djxh from oddfar_campus.dj_clqkxx where clpzh = #{clpzh}")
    Long selectDjxhByClpzh(String clpzh);

    @Select("SELECT phonenumber from oddfar_campus.dj_clqkxx where user_id = #{userId} LIMIT 1")
    Long selectdjxhByuserid(Long userId);
}